done = "jr去完成.jpg"
list = "jr做任务集爆竹.jpg"
award = "jr去领取累计奖励.jpg"

regiony0=700
regiony=1550

function isJD()
    pkg = app.frontPackageName()
    -- toast(pkg)
    -- mSleep(3000)
    bid = "com.jd.jrapp"
    if pkg ~= bid then
        --keycode.recent("京东")
        toast("返回京东金融 App") 
        app.runApp(bid)
        mSleep(3000)
    else
        toast("当前位置：京东金融 App") 
        mSleep(3000)
        wid= widget.find({["text"]="累计任务奖励"})
        if wid == nil then
            keycode.back()
            toast("返回") 
            mSleep(5000) 
        end
    end
end

function getaward()
    x,y = image.findImageInRegion(award,436,899,992,989,500000)--领累计任务奖励
    if x~=-1 and x~=-1 then
        event.tap(x,y)
        mSleep(1000)
        toast("领取累计次数奖励~") 
        mSleep(1000)
        event.tap(530,1595)
        mSleep(3000)
    end
end

function backtolist()
    wid= widget.find({["text"]="累计任务奖励"})
    if wid == nil then
        keycode.back()
        toast("返回") 
        mSleep(5000) 
    end 
end

while true do
    isJD()
    x,y = image.findImageInRegion(list,816,763,1071,1632,500000)--做任务集爆竹
    if x~=-1 and x~=-1 then
        event.tap(x,y)
        toast("做任务集爆竹") 
        mSleep(3000)
    end
   
    wid= widget.find({["text"]="累计任务奖励"})
    if  wid  then
        getaward()
        x,y = image.findImageInRegion(done,744,regiony0,984,regiony,500000)--去完成任务
        if x~=-1 and x~=-1 then
            event.tap(x,y)
            toast("去完成然后等待 15 秒") 
            mSleep(15*1000)
            wid= widget.find({["text"]="累计任务奖励"})
            if wid == nil then
                keycode.back()
                toast("返回") 
                mSleep(5000) 
                backtolist()
            end
        end
    end
end